﻿using System.Collections.Generic;
using FluentValidation;
using Spaanjaars.ContactManager.Infrastructure.Validation;

namespace Spaanjaars.ContactManager.Model.Validation
{
    public class FluentValidationAdapterBase<T> : AbstractValidator<T>, IDomainObjectValidator<T>
    {
        public IList<IBrokenRule> RulesBrokenBy(T entity)
        {
            var brokenRules = new List<IBrokenRule>();
            var validationResult = Validate(entity);

            foreach (var error in validationResult.Errors)            
                brokenRules.Add(new BrokenRule(error.PropertyName, error.ErrorMessage));            

            return brokenRules;
        }
    }
}